//
//  JXTabBarController.swift
//  sinaWeibo
//
//  Created by jixiao on 15/12/27.
//  Copyright © 2015年 heimacast. All rights reserved.
//

import UIKit

class JXTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        //自定义一个tabbar用来重新布局,并且添加一个加号按钮
        
        let tabBar=JXTabBar()
        
        //不能直接复制,直接复制报错,我们间接来赋值
//        self.tabBar=JXTabBar()
        
        tabBar.didClickBack={
            
            print("nihao")
        }
        
        //利用KVC
        setValue(tabBar, forKeyPath: "tabBar")
        

        addControllers()
        
        
    }
    
    func addControllers(){
        
        // Do any additional setup after loading the view.
        addChildViewController(JXHomeController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(JXMessageController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(JXDiscoverController(), imageName: "tabbar_discover", title: "发现")
        
        
        addChildViewController(JXProfileController(), imageName: "tabbar_profile", title: "我")
        
    }
    
    
    func addChildViewController(vc: UIViewController,imageName:String,title:String) {
        
        vc.title=title
        
        vc.tabBarItem.image=UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.selectedImage=UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置字体选中时是橙色,并且图片显示他本来的颜色
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:"44",NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        
        addChildViewController(JXNavagitionViewController(rootViewController:vc))
        
    }

    

}
